import { BufferData } from "../../Decorator/Decorator";
import { ProtoInfo } from "../Module/Proto/ProtoInfo";

export class ProtobufHelper {

    public static Serialize(type: string, stream: BufferData) {
        const streamType = ProtoInfo.Instance.Root.lookupType(type);
        const streamWrapper = streamType.create(stream);
        const buffer = streamType.encode(streamWrapper).finish();
        return buffer;
    }

    public static Deserialize(type: string, stream: BufferData) {
        const streamType = ProtoInfo.Instance.Root.lookupType(type);
        const buffer = streamType.decode(stream as Uint8Array);
        return buffer;
    }

}